<template>
  <div>
    <el-dialog title="添加" :visible.sync="dialogVisible" width="500px">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="标题" prop="title">
          <el-input v-model="ruleForm.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="内容" prop="content">
          <el-input v-model="ruleForm.content" placeholder="输入内容" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>
<script>
import { notificationpub } from '@/api/table'

export default {

  data() {
    return {
      dialogVisible: false,
      listLoading: true,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: ''
      },
      ruleForm: {
        title: '',
        content: ''

      },
      rules: {
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: 'change' }
        ]

      }

    }
  },
  created() {

  },
  methods: {

    async show(record) {
      this.dialogVisible = true
      this.$refs['ruleForm'] && this.$refs['ruleForm'].resetFields()
    },
    async edit(record) {
      this.dialogVisible = true
      this.$refs['ruleForm'] && this.$refs['ruleForm'].resetFields()

      this.ruleForm = record
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          notificationpub(this.ruleForm).then(res => {
            this.dialogVisible = false
            this.$parent.fetchData()
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }

  }
}
</script>
<style scoped lang="scss">
.el-tag+.el-tag {
  margin-left: 10px;
}

.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}

.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}

.list {
  .item {
    border: 1px solid #c0ccda;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin-top: 10px;

    >div {
      display: flex;

      img {
        margin-right: 15px;
      }
    }

    >i {
      font-size: 20px;
      cursor: pointer;
    }
  }
}
</style>
